<template>
 
 <view >
	 <!-- 导航栏 -->
      <u-navbar title="发布博客"
      title-color="#000000"
	   titleCenter="true"  
	   back-icon-name="/" 
	   title-bold ="false"
	   :is-back="false"  :background="background"
	   back-text ="发布"
	   >	  
	  </u-navbar>

 <!-- 表单 -->
 <u-form ref="uForm" :model="user" >
	 <!-- 标题 -->
 <u-form-item  label-width="120" label-style="120" label="标题" prop="title">
 <u-input textarea placeholder="请输入标题"  :v-model="user.title"></u-input>
 </u-form-item>
 
 <!-- 内容 --> 
 <u-form-item label="内容" textarea placeholder="请输入内容" label-width="120" prop="content">
            <u-input v-model="value" :type="type" :border="border" :height="height" :auto-height="autoHeight" />

 </u-form-item>
   <view class="wrap"> 
            <u-form :model="user" ref="uForm">
     
	 <u-upload :action="action" :file-list="fileList" ></u-upload>
	 

	 
  </u-form-item>
  <u-form-item label-width="140" label-position="left" label="用户类别"
         prop="type_id">
      <u-radio-group v-model="user.type_id" @change="radioGroupChange">
  <u-radio
  @change="radioChange"
  v-for="(item, index) in list" :key="index"
  :name="item.val"
  :disabled="item.disabled"
  >
  {{item.txt}}
  </u-radio>
  </u-radio-group>
  </u-form-item>
  </u-form>

  </view>

 </u-form>
 <u-button @click="publish" >发布</u-button>
 

 
 
 </view>
         
</template>


<script>
 export default {
 data() {
 return {
	 
	 background: {
	 					backgroundColor: '#aaffff',
	 					
	 					// 导航栏背景图
	 					// background: 'url(https://cdn.uviewui.com/uview/swiper/1.jpg) no-repeat',
	 					// 还可以设置背景图size属性
	 					// backgroundSize: 'cover',
	 					
	 					// 渐变色
	 					// backgroundImage: 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
	 				},
					
					value: '',
									type: 'textarea',
									border: true,
									height: 500,
									autoHeight: true,
					
					// 上传图片,连接后端网址
					action: 'http://localhost:8088',
									fileList: [
								
									],
									
					
 
     user:{
     title:"",
     content:"",
	 },
	 list:[{
	 val: '1',
	 txt:"美食",
	 disabled: false
	 },
	 {
	 val: '2',
	 txt:"旅游",
	 disabled: false
	 },
	 {
	 val: '3',
	 txt:"科技",
	 disabled: false
	 },
	 {
	 val:'4',
	 txt:"新闻",
	 disabled:false,
	 },
	 {
	 val:'5',
	 txt:"娱乐",
	 disabled:false,
	 }
	 ]
	 
	 
	 
	 }
	 },
 
 
 //添加规则
 rules:{
 title:[
 {
 required: true,
 message: "请输入内容",
 trigger: ['change','blur'],
 }
 ],
 content:[
 {
 required: true,
 message: "请输入内容",
 trigger: ['change','blur'],
 }
 ]
 },

   onReady() {
 this.$refs.uForm.setRules(this.rules);
 },
 methods: {
	 // 发布
	  publish(){
	  console.log("发布");
	  // 网络提交数据
	  uni.request({
		  // 地址
	  url:'http://localhost:8088/PostBlog',
	  // 请求方式
	  method:"POST",
	  // 请求发送的数据
	  data: this.user,
	  // 返回的数据,响应
	  success:(res)=>{
	  console.log(res);
	  if(res.data.code*1 == 200){
	  							//保存
	  							uni.setStorageSync("user",res.data.result);
	  							uni.navigateTo({
	  								url:"/pages/TRH_pages/ShouYe"
	  							})
	  						}else{
	  							//失败
	  							this.$u.toast("发布失败，请检查网络或其他");
	  						}
	  }
	  })
	  
	  
	
	  },
	  radioChange(e) {
	  //console.log(e.detail)
	  console.log(e,"radio",this.user.type_id)
	   //this.user.leibie = e.detail.value
	   },
	   radioGroupChange(e){
	   console.log(e,"group",this.user.type_id)
	   }
	  },
	  
	  }
	  
	 </script>
	 <style>
   
   
   
	 </style>
	 